// 元素加载优先级计算 Worker
self.onmessage = (e) => {
    const { type, data } = e.data;
    
    if (type === 'calculatePriorities') {
        const { objects, viewportCenter } = data;
        
        const priorities = objects.map(object => {
            const objectCenter = {
                x: object.left + object.width / 2,
                y: object.top + object.height / 2
            };
            
            const distance = Math.sqrt(
                Math.pow(objectCenter.x - viewportCenter.x, 2) +
                Math.pow(objectCenter.y - viewportCenter.y, 2)
            );
            
            return {
                id: object.id,
                priority: 1 / (1 + distance)
            };
        });
        
        // 按优先级排序
        priorities.sort((a, b) => b.priority - a.priority);
        
        self.postMessage({
            type: 'prioritiesCalculated',
            data: priorities
        });
    }
};